(deftemplate s
(slot om)
(slot animal)
(slot tigari)
(slot pozitie)
)
(foreach ?om (create$ englez rus spaniol )
(foreach ?animal (create$ cal lup caine)
(foreach ?tigara (create$ Kent LM LuckyStrike)
(foreach ?p (create$ 1 2 3 )
(assert (s (om ?om) (animal ?animal) (tigari ?tigara) (pozitie ?p))

)
)
)
)
)
(defrule ProblemaCaselor
?id1<-(s (om englez) (animal ?a1) (tigari ?t1) (pozitie ?p1 & 1))
(s (om ?o) (animal ?a & lup) (tigari ?t & : (neq ?t LuckyStrike)) (pozitie ?p ))
(s (om ?oo ) (animal ?aa & ~?a) (tigari ?tt & LuckyStrike & ~?t)(pozitie ?pp & : (eq ?id2<-(s (om rus & ~?o) (animal ?a2 & cal & ~?a1) (tigari ?t2 & ~?t1) (pozitie ?p2 & ?id3<-(s (om spaniol & ~?oo) (animal ?a3 & ~?a1 & ~?a2) (tigari ?t3 & Kent & ~?t1 & ~?t2)))))) 
=>
(printout t " Englezul are un " ?a1 " si fumeaza " ?t1 " casa nr " ?p1 crlf)
(printout t " Rusul are un " ?a2 " si fumeaza " ?t2 " casa nr " ?p2 crlf)
(printout t " Spaniolul are un " ?a3 " si fumeaza " ?t3 " casa nr " ?p3 crlf crlf)
(retract ?id1)
(retract ?id2)
(retract ?id3)
        )
    )
(run)